import Request from 'luch-request';

const init = () => {
  const http = new Request({
    baseURL: 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
    timeout: 100 * 1000,
    method: 'GET',
    header: {
      Accept: 'text/json',
      'Content-Type': 'application/json;charset=UTF-8',
      Authorization: 'Bearer 14fc0280-fc65-462d-ac2d-50178c0212e3',
    },
    // #ifdef H5
    // 跨域请求时是否携带凭证（cookies）仅H5支持（HBuilderX 2.6.15+）
    withCredentials: false,
    // #endif
  });

  return http;
};

export const praiseTextApi = (data) => {
  const http = init();

  return http.request({
    method: 'POST',
    data: {
      model: 'doubao-1-5-thinking-pro-m-250428',
      messages: [
        data.system_prompt ?{
          role: 'system',
          content: data.system_prompt,
        }: null,

        {
          role: 'user',
          content: data.text,
        },
      ].filter(i => i),
    },
  }).then(res => {
    return { data: JSON.stringify(res.data) };
  });
};
